import os
from pathlib import Path
import argparse

IMG_SIZE=[1920,1080]

def generate_gt_file(args):
    with open(os.path.join(args.produce_dir,'gt.txt'),'w')as f:
        label_files = os.listdir(args.origin_dir)
        for file in label_files:
            file_name = os.path.basename(file)
            frame = file_name.split('.')[0].lstrip('0')
            #print(frame)
            with open(os.path.join(args.origin_dir,file),'r') as f1:
                lines = f1.readlines()
                for line in lines:
                    line = line.strip().split()
                    id = line[0]
                    w = int(float(line[4])*IMG_SIZE[0])
                    h = int(float(line[5])*IMG_SIZE[1])
                    x1 = int(float(line[2])*IMG_SIZE[0]-w/2)
                    y1 = int(float(line[3])*IMG_SIZE[1]-h/2)
                    #print(f'x1 {x1} y1 {y1} x2 {x2} y2 {y2}')
                    new_line = f'{frame} {id} {x1} {y1} {w} {h} 1 -1 -1 -1\n'
                    f.write(new_line)










if __name__ =="__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument('--origin_dir',default='./cunstom/labels/train',type=str)
    parser.add_argument('--produce_dir',default='./gt',type=str)
    args = parser.parse_args()
    generate_gt_file(args)